import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore(
  'user',
  () => {
    const user = ref({})
    const theme = ref({
      headerBg: '#fff',
      headerText: '#333',
      asideBg: '#fff',
      asideText: '#333',
      asideHover: '#f5f7fa',
      asideActive: '#409eff'
    })

    const setTheme = data => {
      theme.value = data
    }
    const login = data => {
      user.value = data
    }
    const logout = () => {
      user.value = {}
    }
    const isLogin = computed(() => {
      return user.value.token
    })
    return { user, isLogin, login, logout, theme, setTheme }
  },
  {
    persist: {
      key: 'user',
      storage: localStorage
    }
  }
)
